<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'get';
$return=array();
if(!$_SESSION['cloud_isupwxappversion']){
	$fields=array('id','cloud_id');
	$list=pdo_getall('core_wxapp',array('cloud_id <>'=>0),$fields,'cloud_id');
	if($list){
		$cloud_ids=array_keys($list);
		$cloud_ids=implode(';',$cloud_ids);
		$post=array('cloud_ids'=>$cloud_ids);
		$versions=cloud_request('release.wxapp.check',$post,'',true);
		foreach($versions as $cloud_id=>$version){
			if($version['release']!=$list[$cloud_id]['lasttime']){
				$update['lasttime']=$version['release'];
				$update['version']=$version['version'];
				pdo_update('core_wxapp',$update,array('cloud_id'=>$cloud_id));
			}
		}
		$_SESSION['cloud_isupwxappversion']=true;
	}
}
if($_RQ['op']=='get'){
	$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
	$nowyue = mktime(0,0,0,date('m'),1,date('Y'));
	$yesyue = mktime(0,0,0,date('m')-1,1,date('Y'));
	$return['htmls']=array();
	if($_SESSION['isfounder'] && 0){
		//超级管理员，显示系统信息，暂不启用
		$return['htmls']=array();
	}elseif($_SESSION['user']['type']==3 ||1){
		//非超级管理员，显示站点信息
		//数据统计
		$access=array();
		$access['wechat_day']=pdo_count('core_access_log',array('this'=>2,'os'=>2,'createtime >'=>$daytime));
		$access['wxapp_day']=pdo_count('core_access_log',array('this'=>2,'os'=>1,'createtime >'=>$daytime));
		$access['mobile_day']=pdo_count('core_access_log',array('this'=>2,'os'=>3,'createtime >'=>$daytime));
		$access['pc_day']=pdo_count('core_access_log',array('this'=>2,'os'=>4,'createtime >'=>$daytime));
		$access['app_day']=pdo_count('core_access_log',array('this'=>2,'os'=>5,'createtime >'=>$daytime));
		$access['all_day']=pdo_count('core_access_log',array('this'=>2,'createtime >'=>$daytime));
		$access['wechat_all']=pdo_count('core_access_log',array('this'=>2,'os'=>2));
		$access['wxapp_all']=pdo_count('core_access_log',array('this'=>2,'os'=>1));
		$access['mobile_all']=pdo_count('core_access_log',array('this'=>2,'os'=>3));
		$access['pc_all']=pdo_count('core_access_log',array('this'=>2,'os'=>4));
		$access['app_all']=pdo_count('core_access_log',array('this'=>2,'os'=>5));
		$access['all_all']=pdo_count('core_access_log',array('this'=>2));

		//月份
		for($i=0;$i<12;$i++){
			if($i==0){
				$yuestart = mktime(0,0,0,date('m'),1,date('Y'));
				$yueend = time();
				
			}else{
				$yuestart = mktime(0,0,0,date('m')-$i,1,date('Y'));
				$yueend = mktime(0,0,0,date('m')-$i+1,1,date('Y'));
			}
			$params=array();
			$params['createtime between']=array($yuestart,$yueend);
			$month12[] = date('Y-m',strtotime('-'.$i.' month'));
			//$monthaccess[]=pdo_count('core_access_log',$params);
			$allaccess[]=pdo_count('core_access_log',$params);
			$useraccess[]=pdo_count('core_members',$params);
			$params['status']=1;
			$kehufee[]=pdo_getsum('core_paylog',$params,'fee')?:0;
			$sysfee[]=pdo_getsum('core_account_pay_log',$params,'fee')?:0;
		}
		$allaccess=array_reverse($allaccess);
		$useraccess=array_reverse($useraccess);
		$kehufee=array_reverse($kehufee);
		$sysfee=array_reverse($sysfee);
		$month12=array_reverse($month12);
		$intypes=get_plugin_intypes();
		$inlist=array();
		foreach($intypes as $k=>&$inv){
			if($k){
				$inlist[$k]['name']='core';
				$inlist[$k]['title']=$inv;
				$inlist[$k]['action']='/account.apphome//type='.$k;
			}else{
				$inlist[18]['name']='core';
				$inlist[18]['title']=$inv;
				$inlist[18]['action']='/account.apphome//type=0';
			}
		}
		$version=core_setting('version');
		$version['version']=$version['version']?:'1.0.1';
		$newversion = cache_read('cloud_newversion');
		if(!$newversion){
			$newversion = cloud_request('release.get_data.getnew');
			cache_write('cloud_newversion',$newversion);
		}
		$vtitle='V'.$version['version'];
		if($version['version'] !=$newversion['version']){
			$version['release']=date('Y-m-d',$version['release']);
			$subtitle='版本更新日期:'.$version['release'];
		}else{
			$subtitle='当前版本即最新版本，无须升级';
		}
		$navs=array(0=>'推荐乐高体',1=>'新应用',2=>'推荐应用',3=>'小程序',4=>'互动营销活动');
		$system=core_setting('system');
		if($system['backsqldata']){
			$days=intval((time()-$system['backsqldata'])/86400);
			$dbtitle=$days.'天';
			$dbsubtitle='没有备份数据库了,请及时备份!';
		}else{
			$dbtitle='还未备份';
			$dbsubtitle='请及时备份!';
		}
		$getapps = cache_read('cloud_getapps');
		if(!$getapps){
			$getapps=cloud_request('release.get_data.siteapps',$params,'',true);
			cache_write('cloud_getapps',$getapps);
		}
		$getapps=json_decode($getapps,true);
		$apps[0]=$getapps['legao'];
		$apps[1]=$getapps['new'];
		$apps[2]=$getapps['plugin'];
		$apps[3]=$getapps['wxapp'];
		$apps[4]=$getapps['game'];
		$getnews = cache_read('cloud_getnews');
		if(!$getnews){
			$getnews=cloud_request('release.get_data.sitenews',$params,'',true);
			cache_write('cloud_getnews',$getnews);
		}
		$getnews=json_decode($getnews,true);
		$newslist[0]=$getnews['news'];
		$newslist[1]=$getnews['help'];
		$newsnavs=array(0=>'热点公告',1=>'使用手册');
		$ads = cache_read('cloud_ads');	
		if(!$ads){
			$ads=cloud_request('release.get_data.sitead',$params,'',true);
			cache_write('cloud_ads',$ads);
		}
		$ads=json_decode($ads,true);
		if($ads['hd_topimg']){
			$adshow=true;
		}
		$return['item']['ad_img']=$ads['hd_topimg'];
		$return['item']['newslist']=$newslist;
		$return['item']['apps']=$apps;
		$return['item']['groupid']=0;
		$return['item']['typeid']=0;
		$return['htmls']=array(
				array('type'=>'ad_img','name'=>'ad_img','url'=>$ads['huodonglink'],'adshow'=>$adshow,'width'=>'100%','height'=>'80px'),
				array('type'=>'echarts_arealine','ecid'=>'mobile','title'=>'访问/流水数据指标_Access data','datas'=>array(
					'datas'=>array(
						array('name'=>'访问次数','value'=>$allaccess),
						array('name'=>'客户流水','value'=>$kehufee),
						array('name'=>'平台流水','value'=>$sysfee),
						array('name'=>'新增会员','value'=>$useraccess),
					),
					'xdatas'=>$month12,
				)),
				array('type'=>'data','tpltype'=>4,'one_num'=>4,'title'=>'站点今日/总访问数据指标_site today/all access data','datas'=>array(
					array('title'=>'公众号访问数据','num'=>2,'data'=>array($access['wechat_day'],$access['wechat_all'])),
					array('title'=>'小程序访问数据','bgcolor'=>'#009933','num'=>2,'data'=>array($access['wxapp_day'],$access['wxapp_all'])),
					array('title'=>'H5端访问数据','bgcolor'=>'#3366FF','num'=>2,'data'=>array($access['mobile_day'],$access['mobile_all'])),
					array('title'=>'PC端访问数据','bgcolor'=>'#FF3300','num'=>2,'data'=>array($access['pc_day'],$access['pc_all'])),
				)),
				array('type'=>'data','tpltype'=>7,'width'=>'50%','icon'=>'fa-files-o','title'=>'系统更新_Up data','url'=>'cloud.update/','vtitle'=>$vtitle,'subtitle'=>$subtitle,'btntitle'=>'检测更新'),
				array('type'=>'data','tpltype'=>7,'width'=>'50%','icon'=>'fa-cogs','title'=>'数据备份_Up data','url'=>'system.db/','vtitle'=>$dbtitle,'subtitle'=>$dbsubtitle,'btntitle'=>'去备份'),
				array('type'=>'storeplugins','name'=>'groupid','title'=>'推荐应用_Up apps','url'=>'system.update/','navs'=>$navs,'apps'=>'apps','btntitle'=>'去应用市场 >>'),
				array('type'=>'storenews','name'=>'typeid','title'=>'进云头条_Up news','navs'=>$newsnavs,'apps'=>'newslist','btntitle'=>'查看更多公告 >>'),
		);
	}
	$system=core_setting('site');
	$site=pdo_get('core_accounts',array('uniacid'=>$_SESSION['uniacid']),array('title','logo','desc','ewm','credit2','groupid'));
	$site['share_url']= SITEROOT.'./manage/index.php?plugin=core&action=account.welcome&uid='.$_SESSION['uniacid'];
	if($site['groupid']){
		$plugin_name=pdo_getcolumn('core_account_group',array('id'=>$site['groupid']),'plugin_name');
		$is_legao=pdo_getcolumn('core_plugins',array('name'=>$plugin_name),'is_legao');	
	}
	if($system['guide_group']!=1 && !$is_legao && !$_SESSION['isfounder'] && $_SESSION['user']['type']==3){
		array_unshift($return['htmls'],array('type'=>'guide_modal','tpltype'=>1,'title'=>'常用产品'));
	}
	$iswechat=pdo_getcolumn('core_account_wechat',array('uniacid'=>$_SESSION['uniacid']),'id');
	if($_SESSION['os']=='windows'){
		if($_SESSION['isfounder'] && (empty($system['title']) || empty($system['name']))){
			$return['htmls'][]=array('type'=>'intro','title'=>'新手引导','datas'=>array(
				array('element'=>'#top_nav_item_0','intro'=>'创始人您好！您还没有设置好系统噢！</br>只有设置好了平台，才能有好的驰骋！点这里开始->系统设置->页面信息设置噢！','position'=>''),
			));
		}elseif(empty($site['title']) || empty($site['desc'])){
			$return['htmls'][]=array('type'=>'intro','title'=>'新手引导','datas'=>array(
				array('element'=>'#top_nav_item_1','intro'=>'主人您好！您还没有设置好站点信息噢！</br>只有设置好了信息，才能有好的体验！点站点设置->基本设置','position'=>''),
			));
		}elseif($_SESSION['uniacid']==1 && empty($iswechat)){
			$return['htmls'][]=array('type'=>'intro','title'=>'新手引导','datas'=>array(
				array('element'=>'#top_nav_item_2','intro'=>'创始人您好！您还没有添加默认公众号噢！</br>这点很重要，是激活平台,实现扫码登录，粉丝同步的关键！站点平台->公众号管理！','position'=>''),
			));
		}elseif(empty($iswechat)){
			$return['htmls'][]=array('type'=>'intro','title'=>'新手引导','datas'=>array(
				array('element'=>'#top_nav_item_2','intro'=>'主人您好！您还没有添加默认公众号噢！</br>添加了默认有效的公众号，才能实现扫码登录，粉丝同步，微信支付等体验！站点平台->公众号管理！','position'=>''),
			));
		}
	}
	
	$fields=array('id','title','paixu','status','group_id','content','type');
		$orderby=' id desc';
		$total='';
		$return['notice']=pdo_getslice('core_article',array('status'=>1,'type'=>2), ' LIMIT 8', $total,$fields,'',$orderby);
		$operating=core_setting('operating');
		$return['site']=$site;
		$return['operating']=$operating;
		$return['access']=$access;
		$return['wechat']=$wechat;
		$return['wxapp']=$wxapp;
		$return['mobile']=$mobile;
		$return['pc']=$pc;
		set_html('title','系统后台');
		set_html('header','common/header');
		exi($return);
}
if($_RQ['op']=='add_quick'){
	$postdata=get_postdata();
	$data=array(
		'uid'=>$_SESSION['uid'],
		'action'=>trim($postdata['action']),
		'plugin'=>trim($postdata['plugin']),
		'op'=>trim($postdata['op']),
		'query'=>trim($postdata['query']),
		'title'=>trim($postdata['title']),
		'html'=>trim($postdata['html'])
	);
	pdo_insert('core_user_quick',$data);
	$id=pdo_insertid();
	$res=array('id'=>$id,'type'=>'success');
	exi($res);
}
if($_RQ['op']=='set_quick'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$id=intval($post['id']);
		if(!$id){
			exi('请先设置要保存的快捷方式！','error');
		}
		$update=array_fields(array('title'),$post);
		pdo_update('core_user_quick',$update,array('id'=>$id,'uid'=>$_SESSION['uid']));
		exi('操作成功！');
	}
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择要设置的快捷方式！','error');
	}
	$item=pdo_get('core_user_quick',array('id'=>$id,'uid'=>$_SESSION['uid']),array('id','title'));
	if(!$item){
		exi('要编辑设置的快捷方式不存在！','error');
	}
	$return['item']=$item;
	$return['htmls']=array(
		'type'=>'edit',
		'edit'=>array(
			array('type'=>'string','name'=>'title','title'=>'快捷方式名称'),
		),
	);
	exi($return);
}
if($_RQ['op']=='del'){
	$id=intval($_RQ['id']);
	if($id){
		pdo_delete('core_user_quick',array('id'=>$id,'uid'=>$_SESSION['uid']));
	}
	exi('删除成功！');
}
if($_RQ['op']=='getintype'){
	$intypes=get_plugin_intypes();
	$inlist=array();
	foreach($intypes as $k=>&$inv){
			if($k){
				$inlist[$k]['title']=$inv;
			}else{
				$inlist[18]['title']=$inv;
			}
	}
	foreach($inlist as $k=>&$ig){
			$groups=pdo_getall('core_account_group');
			foreach($groups as $kg=>&$gg){
				$intype=pdo_getcolumn('core_plugins',array('name'=>$gg['plugin_name']),'intype');
				if($k==$intype){
					$ig['groups'][]=$gg;
				}
			}
	}
	$return['list']=$inlist;
	exi($return);
}
?>